package com.subang.function.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.subang.function.mapper.SbUserStudyGroupMapper;
import com.subang.function.domain.SbUserStudyGroup;
import com.subang.function.service.ISbUserStudyGroupService;

/**
 * 用户 - 小组关联Service业务层处理
 * 
 * @author subei
 * @date 2025-03-29
 */
@Service
public class SbUserStudyGroupServiceImpl implements ISbUserStudyGroupService 
{
    @Autowired
    private SbUserStudyGroupMapper sbUserStudyGroupMapper;

    /**
     * 查询用户 - 小组关联
     * 
     * @param id 用户 - 小组关联主键
     * @return 用户 - 小组关联
     */
    @Override
    public SbUserStudyGroup selectSbUserStudyGroupById(Long id)
    {
        return sbUserStudyGroupMapper.selectSbUserStudyGroupById(id);
    }

    /**
     * 查询用户 - 小组关联列表
     * 
     * @param sbUserStudyGroup 用户 - 小组关联
     * @return 用户 - 小组关联
     */
    @Override
    public List<SbUserStudyGroup> selectSbUserStudyGroupList(SbUserStudyGroup sbUserStudyGroup)
    {
        return sbUserStudyGroupMapper.selectSbUserStudyGroupList(sbUserStudyGroup);
    }

    /**
     * 新增用户 - 小组关联
     * 
     * @param sbUserStudyGroup 用户 - 小组关联
     * @return 结果
     */
    @Override
    public int insertSbUserStudyGroup(SbUserStudyGroup sbUserStudyGroup)
    {
        return sbUserStudyGroupMapper.insertSbUserStudyGroup(sbUserStudyGroup);
    }

    /**
     * 修改用户 - 小组关联
     * 
     * @param sbUserStudyGroup 用户 - 小组关联
     * @return 结果
     */
    @Override
    public int updateSbUserStudyGroup(SbUserStudyGroup sbUserStudyGroup)
    {
        return sbUserStudyGroupMapper.updateSbUserStudyGroup(sbUserStudyGroup);
    }

    /**
     * 批量删除用户 - 小组关联
     * 
     * @param ids 需要删除的用户 - 小组关联主键
     * @return 结果
     */
    @Override
    public int deleteSbUserStudyGroupByIds(Long[] ids)
    {
        return sbUserStudyGroupMapper.deleteSbUserStudyGroupByIds(ids);
    }

    /**
     * 删除用户 - 小组关联信息
     * 
     * @param id 用户 - 小组关联主键
     * @return 结果
     */
    @Override
    public int deleteSbUserStudyGroupById(Long id)
    {
        return sbUserStudyGroupMapper.deleteSbUserStudyGroupById(id);
    }

    @Override
    public int deleteSbUserStudyGroupByGroupId(String groupId) {
        return sbUserStudyGroupMapper.deleteSbUserStudyGroupByGroupId(groupId);
    }

    @Override
    public List<String> selectGroupIdsByUserId(Long userId) {
        SbUserStudyGroup query = new SbUserStudyGroup();
        query.setUserId(userId);
        List<SbUserStudyGroup> list = sbUserStudyGroupMapper.selectSbUserStudyGroupList(query);
        return list.stream().map(SbUserStudyGroup::getGroupId).collect(Collectors.toList());
    }

    @Override
    public int deleteSbUserStudyGroupByUserIdAndGroupId(Long userId, String groupId) {
        return sbUserStudyGroupMapper.deleteSbUserStudyGroupByUserIdAndGroupId(userId , groupId);
    }
}
